import sys
import operator

inputFileName = "/data1/team/weijiang/machine-learning-project-related/featuresGenerated/auxFiles/queryID_term_docID_pair"
outputFileName = "/data1/team/weijiang/machine-learning-project-related/featuresGenerated/auxFiles/queryID_term_docID_pair_sorted_by_doc_id"

inputFileHandler = open(inputFileName,"r")
outputFileHandler = open(outputFileName, "w")

lineElementsList = []
for currentLine in inputFileHandler:
    lineElementsList.append( (currentLine.strip().split(" ")[0], currentLine.strip().split(" ")[1], int( currentLine.strip().split(" ")[2]) ) )

lineElementsList.sort(cmp=None, key=operator.itemgetter(2,1) , reverse=False) 
for currentLineElements in lineElementsList:
    #print currentLineElements
    outputFileHandler.write(currentLineElements[0] + " " + currentLineElements[1] + " " + str( currentLineElements[2] ) + "\n")
    
outputFileHandler.close()
print "Job Done!"
# that is good.


    